<!doctype html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=robots content="noodp"><meta http-equiv=x-ua-compatible content="IE=edge, chrome=1"><title>Eclipse问题汇总 - Yulin Lewis' Blog</title><meta name=keywords content="雨临Lewis,Java,hugo,hexo,博客"><meta name=Description content="不想当写手的码农不是好咸鱼_(xз」∠)_"><meta property="og:title" content="Eclipse问题汇总"><meta property="og:description" content="Access restriction: The type &lsquo;JPEGCodec&rsquo; is not API
导入项目时Eclipse报错如下：


1


Access restriction: The type 'JPEGCodec' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar')


第一次遇到这种错误，百度了下，原来是因为Eclipse默认把访问受限的API设置成了Error级别，所以才会编译报错。"><meta property="og:type" content="article"><meta property="og:url" content="https://lewky.cn/posts/eclipse-issues/"><meta property="og:image" content="https://lewky.cn/logo.png"><meta property="article:published_time" content="2019-01-18T23:04:49+08:00"><meta property="article:modified_time" content="2022-01-12T23:04:49+08:00"><meta name=twitter:card content="summary_large_image"><meta name=twitter:image content="https://lewky.cn/logo.png"><meta name=twitter:title content="Eclipse问题汇总"><meta name=twitter:description content="Access restriction: The type &lsquo;JPEGCodec&rsquo; is not API
导入项目时Eclipse报错如下：


1


Access restriction: The type 'JPEGCodec' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar')


第一次遇到这种错误，百度了下，原来是因为Eclipse默认把访问受限的API设置成了Error级别，所以才会编译报错。"><meta name=application-name content="雨临Lewis的博客"><meta name=apple-mobile-web-app-title content="雨临Lewis的博客"><meta name=theme-color content="#ffffff"><meta name=msapplication-TileColor content="#da532c"><link rel="shortcut icon" type=image/x-icon href=/favicon.ico><link rel=icon type=image/png sizes=32x32 href=/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/favicon-16x16.png><link rel=apple-touch-icon sizes=180x180 href=/apple-touch-icon.png><link rel=mask-icon href=/safari-pinned-tab.svg color=#5bbad5><link rel=manifest href=/site.webmanifest><link rel=canonical href=https://lewky.cn/posts/eclipse-issues/><link rel=prev href=https://lewky.cn/posts/a28e251d.html/><link rel=next href=https://lewky.cn/posts/9af9bb6b.html/><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css><link rel=stylesheet href=/css/style.min.css><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/animate.css@3.7.2/animate.min.css><script type=application/ld+json>{"@context":"http://schema.org","@type":"BlogPosting","headline":"Eclipse问题汇总","inLanguage":"","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/lewky.cn\/posts\/eclipse-issues\/"},"genre":"posts","keywords":"Eclipse, 工作记录","wordcount":4689,"url":"https:\/\/lewky.cn\/posts\/eclipse-issues\/","datePublished":"2019-01-18T23:04:49+08:00","dateModified":"2022-01-12T23:04:49+08:00","license":"This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher":{"@type":"Organization","name":"雨临Lewis","logo":"https:\/\/lewky.cn\/images\/avatar.jpg"},"author":{"@type":"Person","name":"雨临Lewis"},"description":""}</script></head><body header-desktop=fixed header-mobile=auto><script type=text/javascript>(window.localStorage&&localStorage.getItem('theme')?localStorage.getItem('theme')==='dark':('auto'==='auto'?window.matchMedia('(prefers-color-scheme: dark)').matches:'auto'==='dark'))&&document.body.setAttribute('theme','dark');</script><div id=mask></div><div class=wrapper><header class=desktop id=header-desktop><div class=header-wrapper><a href=https://github.com/lewky class=github-corner target=_blank title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="3.5rem" height="3.5rem" viewBox="0 0 250 250" style="fill:#70b7fd;color:#fff;position:absolute;top:0;border:0;left:0;transform:scale(-1,1)" aria-hidden="true"><path d="M0 0 115 115h15l12 27L250 250V0z"/><path d="M128.3 109C113.8 99.7 119 89.6 119 89.6 122 82.7 120.5 78.6 120.5 78.6 119.2 72 123.4 76.3 123.4 76.3 127.3 80.9 125.5 87.3 125.5 87.3 122.9 97.6 130.6 101.9 134.4 103.2" fill="currentcolor" style="transform-origin:130px 106px" class="octo-arm"/><path d="M115 115C114.9 115.1 118.7 116.5 119.8 115.4L133.7 101.6C136.9 99.2 139.9 98.4 142.2 98.6 133.8 88 127.5 74.4 143.8 58 148.5 53.4 154 51.2 159.7 51 160.3 49.4 163.2 43.6 171.4 40.1 171.4 40.1 176.1 42.5 178.8 56.2 183.1 58.6 187.2 61.8 190.9 65.4 194.5 69 197.7 73.2 200.1 77.6 213.8 80.2 216.3 84.9 216.3 84.9 212.7 93.1 206.9 96 205.4 96.6 205.1 102.4 203 107.8 198.3 112.5 181.9 128.9 168.3 122.5 157.7 114.1 157.9 116.9 156.7 120.9 152.7 124.9L141 136.5C139.8 137.7 141.6 141.9 141.8 141.8z" fill="currentcolor" class="octo-body"/></svg></a><div class=header-title><a href=/ title="Yulin Lewis' Blog"><span class=header-title-pre><i class="fas fa-fw fa-atom"></i></span>雨临Lewis</a></div><div class=menu><div class=menu-inner><div class=dropdown><a href=/posts/ class="menu-item menu-more dropbtn" title=点击查看所有文章><i class="fas fa-fw fa-archive"></i>归档</a><div class="menu-more-content dropdown-content"><a href=/categories/><i class="fas fa-fw fa-th"></i>分类 </a><a href=/tags/><i class="fas fa-fw fa-tag"></i>标签 </a><a href=/hot/ title=文章热度Top15><i class="fas fa-fw fa-fire"></i>热度 </a><a href=/donation/ title=感谢打赏，老板大气~><i class="fas fa-fw fa-donate"></i>打赏 </a><a href=/about/><i class="fas fa-fw fa-at"></i>关于</a></div></div><a class=menu-item href=/friends/ title=欢迎申请友链><i class="fas fa-fw fa-link"></i>友链</a><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn" title=一些有意思的东东~><i class="fas fa-fw fa-fan fa-spin"></i>趣味</a><div class="menu-more-content dropdown-content"><a href=/funny/high/ title="前方高能♂ 小心外放！" target=_blank rel=noopener><i class="fas fa-fw fa-dizzy"></i>燥起来！ </a><a href=/funny/mikutap/ title=初音未来音乐游戏 target=_blank rel=noopener><i class="fas fa-fw fa-music"></i>在线打碟 </a><a href=/funny/catch-the-cat/ title=逮住那只猫!><i class="fas fa-fw fa-cat"></i>抓住猫咪</a></div></div><div class=dropdown><a href=/ class="menu-item menu-more dropbtn" title=回到首页><i class="fas fa-fw fa-atom"></i>站点</a><div class="menu-more-content dropdown-content"><a href=/bbs/ title=来留言吧~><i class="fas fa-fw fa-comment"></i>公告留言 </a><a href=https://seo.chinaz.com target=_blank rel=noopener><i class="fas fa-fw fa-chart-line"></i>SEO查询 </a><a href=https://www.ping.cn/http/lewky.cn target=_blank rel=noopener><i class="fas fa-fw fa-bezier-curve"></i>网站测速 </a><a href=/posts/e62c38c4.html/><i class="fas fa-fw fa-cog fa-spin"></i>建站日志</a></div></div><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn"><i class="fas fa-fw fa-book"></i>文档</a><div class="menu-more-content dropdown-content"><a href=https://gohugo.io/documentation/ target=_blank rel=noopener><i class="fas fa-fw fa-star"></i>Hugo文档 </a><a href=https://javanote.doc.lewky.cn/ title=尚在完善中~ target=_blank rel=noopener><i class="fab fa-fw fa-java"></i>Java 笔记</a></div></div><a class=menu-item href=/search/ title=渲染搜索结果需要等待几秒钟~><i class="fas fa-fw fa-search"></i>搜索
</a><span class="menu-item delimiter"></span><a href=https://travellings.link target=_blank class=menu-item rel=noopener title=开往-友链接力><i class="fas fa-fw fa-subway"></i></a><a href=https://rssblog.vercel.app/ class=menu-item target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i></a><a href=https://github.com/lewky class=menu-item target=_blank rel=noopener title=GitHub><i class="fab fa-fw fa-github"></i></a></div></div></div></header><header class=mobile id=header-mobile><div class=header-container><div class=header-wrapper><div class=header-title><a href=/ title="Yulin Lewis' Blog"><span class=header-title-pre><i class="fas fa-fw fa-atom"></i></span>雨临Lewis</a></div><div class=menu-toggle id=menu-toggle-mobile><span></span><span></span><span></span></div></div><div class=menu id=menu-mobile><div class=dropdown><a href=/posts/ class="menu-item menu-more dropbtn" title=点击查看所有文章><i class="fas fa-fw fa-archive"></i>归档</a><div class="menu-more-content dropdown-content"><a href=/categories/><i class="fas fa-fw fa-th"></i>分类 </a><a href=/tags/><i class="fas fa-fw fa-tag"></i>标签 </a><a href=/hot/ title=文章热度Top15><i class="fas fa-fw fa-fire"></i>热度 </a><a href=/donation/ title=感谢打赏，老板大气~><i class="fas fa-fw fa-donate"></i>打赏 </a><a href=/about/><i class="fas fa-fw fa-at"></i>关于</a></div></div><a class=menu-item href=/friends/ title=欢迎申请友链><i class="fas fa-fw fa-link"></i>友链</a><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn" title=一些有意思的东东~><i class="fas fa-fw fa-fan fa-spin"></i>趣味</a><div class="menu-more-content dropdown-content"><a href=/funny/high/ title="前方高能♂ 小心外放！" target=_blank rel=noopener><i class="fas fa-fw fa-dizzy"></i>燥起来！ </a><a href=/funny/mikutap/ title=初音未来音乐游戏 target=_blank rel=noopener><i class="fas fa-fw fa-music"></i>在线打碟 </a><a href=/funny/catch-the-cat/ title=逮住那只猫!><i class="fas fa-fw fa-cat"></i>抓住猫咪</a></div></div><div class=dropdown><a href=/ class="menu-item menu-more dropbtn" title=回到首页><i class="fas fa-fw fa-atom"></i>站点</a><div class="menu-more-content dropdown-content"><a href=/bbs/ title=来留言吧~><i class="fas fa-fw fa-comment"></i>公告留言 </a><a href=https://seo.chinaz.com target=_blank rel=noopener><i class="fas fa-fw fa-chart-line"></i>SEO查询 </a><a href=https://www.ping.cn/http/lewky.cn target=_blank rel=noopener><i class="fas fa-fw fa-bezier-curve"></i>网站测速 </a><a href=/posts/e62c38c4.html/><i class="fas fa-fw fa-cog fa-spin"></i>建站日志</a></div></div><div class=dropdown><a href=javascript:void(0); class="menu-item menu-more dropbtn"><i class="fas fa-fw fa-book"></i>文档</a><div class="menu-more-content dropdown-content"><a href=https://gohugo.io/documentation/ target=_blank rel=noopener><i class="fas fa-fw fa-star"></i>Hugo文档 </a><a href=https://javanote.doc.lewky.cn/ title=尚在完善中~ target=_blank rel=noopener><i class="fab fa-fw fa-java"></i>Java 笔记</a></div></div><a class=menu-item href=/search/ title=渲染搜索结果需要等待几秒钟~><i class="fas fa-fw fa-search"></i>搜索</a>
<a href=https://travellings.link target=_blank class=menu-item rel=noopener title=开往-友链接力><i class="fas fa-fw fa-subway"></i></a><a href=https://rssblog.vercel.app/ class=menu-item target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i></a><a href=https://github.com/lewky class=menu-item target=_blank rel=noopener title=GitHub><i class="fab fa-fw fa-github"></i></a></div></div></header><div class="search-dropdown desktop"><div id=search-dropdown-desktop></div></div><div class="search-dropdown mobile"><div id=search-dropdown-mobile></div></div><main class=main><div class=container><div class=toc id=toc-auto><h2 class=toc-title>目录</h2><div class=toc-content id=toc-content-auto></div></div><article class="page single"><h1 class="single-title animated flipInX">Eclipse问题汇总</h1><div class=post-meta><div class=post-meta-line><span class=post-author><a href=/ title=Author rel=author class=author><i class="fas fa-user-circle fa-fw"></i>雨临Lewis</a></span>&nbsp;<span class=post-category>收录于 <a href=/categories/ide%E5%B7%A5%E5%85%B7/><i class="far fa-folder fa-fw"></i>IDE工具</a></span></div><div class=post-meta-line><i class="far fa-calendar fa-fw"></i>&nbsp;<time datetime=2019-01-18>2019-01-18</time>&nbsp;<i class="far fa-calendar-plus fa-fw"></i>&nbsp;<time datetime=2022-01-12>2022-01-12</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 4689 字
<i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 10 分钟&nbsp;<span id=/posts/eclipse-issues/ class=leancloud_visitors data-flag-title=Eclipse问题汇总>
<i class="far fa-eye fa-fw"></i>&nbsp;<span class=leancloud-visitors-count></span>&nbsp;次阅读
</span>&nbsp;
<a href=#comments id=post-meta-vcount title=查看评论><i class="fas fa-comment fa-fw"></i>&nbsp;<span id=/posts/eclipse-issues/ class=waline-comment-count></span>&nbsp;条评论</a></div></div><div class="details toc" id=toc-static kept><div class="details-summary toc-title"><span>目录</span>
<span><i class="details-icon fas fa-angle-right"></i></span></div><div class="details-content toc-content" id=toc-content-static><nav id=TableOfContents><ol><li><a href=#access-restriction-the-type-jpegcodec-is-not-api>Access restriction: The type &lsquo;JPEGCodec&rsquo; is not API</a><ol><li><a href=#解决方法一推荐>解决方法一（推荐）</a></li><li><a href=#解决方法二>解决方法二</a></li></ol></li><li><a href=#缺少servlet-apijar包>缺少servlet-api.jar包</a></li><li><a href=#怎么设置在启动时提示选择工作空间>怎么设置在启动时提示选择工作空间</a></li><li><a href=#如何在新的工作空间使用原来的配置编码视图快捷键插件设置等>如何在新的工作空间使用原来的配置(编码、视图、快捷键、插件设置等)</a></li><li><a href=#接口实现类里使用override注解报错>接口实现类里使用@Override注解报错</a><ol><li><a href=#解决方法>解决方法</a></li></ol></li><li><a href=#修改默认编码为utf-8>修改默认编码为utf-8</a></li><li><a href=#修改properties文件的编码>修改properties文件的编码</a></li><li><a href=#如何修改web项目的web-module-version>如何修改web项目的web module version</a><ol><li><a href=#解决办法>解决办法</a></li></ol></li><li><a href=#maven项目update-project后jdk版本变成15>Maven项目Update Project后jdk版本变成1.5</a><ol><li><a href=#方法一在pom文件中指明jdk版本>方法一：在pom文件中指明jdk版本</a></li><li><a href=#方法二修改settingsxml文件>方法二：修改settings.xml文件</a></li></ol></li><li><a href=#安装了jd-eclipse插件后依然无法反编译类文件>安装了jd-eclipse插件后依然无法反编译类文件</a></li><li><a href=#eclipse无法找到mapstruct生成的mapper实现类>Eclipse无法找到MapStruct生成的mapper实现类</a></li><li><a href=#弹窗提示-code-recommenders-cannot-download-its-model-repository-index>弹窗提示 code recommenders cannot download its model repository index</a></li><li><a href=#eclipse无法搜索到本地仓库的jar包>Eclipse无法搜索到本地仓库的jar包</a></li><li><a href=#启动springboot项目报错-error-could-not-find-or-load-main-class>启动SpringBoot项目报错： Error: Could not find or load main class</a></li><li><a href=#参考链接>参考链接</a></li></ol></nav></div></div><div class=content id=content><h2 id=access-restriction-the-type-jpegcodec-is-not-api>Access restriction: The type &lsquo;JPEGCodec&rsquo; is not API</h2><p>导入项目时Eclipse报错如下：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-fallback data-lang=fallback>Access restriction: The type &#39;JPEGCodec&#39; is not API (restriction on required library &#39;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar&#39;)
</code></pre></td></tr></table></div></div><p>第一次遇到这种错误，百度了下，原来是因为Eclipse默认把访问受限的API设置成了Error级别，所以才会编译报错。</p><h3 id=解决方法一推荐>解决方法一（推荐）</h3><p>直接将项目的JRE给remove掉，然后再重新将JRE添加到项目中，操作如下：</p><ol><li>右键项目，选择Properties -> Java Build Path -> Libraries -> 选中JRE System Library [jdkxxxx] -> 选择<code>Remove</code></li><li>接着选择<code>Add Librariy...</code>，重新加入JRE</li></ol><h3 id=解决方法二>解决方法二</h3><p>修改Eclipse中关于访问受限的API的编译级别：</p><p>Window -> Preferences -> Java -> Compiler -> Errors/Warnings，选择<code>Deprecated and restricted API</code>，将其中的<code>Forbidden reference(access rules)</code>的级别选为Warning。</p><h2 id=缺少servlet-apijar包>缺少servlet-api.jar包</h2><p>在Eclipse中缺省servlet-api.jar包，由于servlet-api.jar以及jsp-api.jar这两个jar包含在Apache Tomcat中，所以提示这两个包缺省而出现错误的情况下，执行Build Path -> Configure Build path -> Libraries -> Add Library -> server Runtime就可以了。</p><h2 id=怎么设置在启动时提示选择工作空间>怎么设置在启动时提示选择工作空间</h2><ol><li>Window -> Preferences -> General -> Startup and Shutdown -> Workspaces</li><li>勾选`Prompt for workspace on startup</li></ol><h2 id=如何在新的工作空间使用原来的配置编码视图快捷键插件设置等>如何在新的工作空间使用原来的配置(编码、视图、快捷键、插件设置等)</h2><p>Eclipse如果更换一个新的工作空间，需要重新设置视图、配置等一系列东西，算是想到麻烦的一件事情，其实我们完全可以将旧的工作空间里的配置拷贝到新的工作空间里，这样就可以省去重新配置的麻烦了~ </p><p>具体操作如下：</p><p>在<code>${workspace(你电脑里原本的工作空间目录)}/.metadata/.plugins</code>里有这样两个文件夹：<code>org.eclipse.core.runtime</code>和<code>org.eclipse.ui.workbench</code>，将新的工作空间里的同名文件夹删了，再将这两个文件夹复制到新的工作空间就行了！</p><p><code>org.eclipse.core.runtime</code>：保存着Eclipse的用户配置，包括视图、编码、各种插件的配置(window下的preference里边的插件配置)等</p><p><code>org.eclipse.ui.workbench</code>：保持着ui上的配置，包括上方的快捷工具栏和下方的view窗口等</p><p>如果不知道自己正在使用的工作空间在哪个目录下，请点击Eclipse左上角的<code>File→switch workspace→other</code>，显示的就是当前工作空间的目录。另外，在这里有个<code>copy setting</code>，可以选择转换到新的工作空间时拷贝原本的配置，但这里拷贝的其实只是<code>org.eclipse.ui.workbench</code>，缺少了<code>org.eclipse.core.runtime</code>，所以这种方法会丢失部分配置。</p><p>另外不要没事就随便转换工作空间，Eclipse容易崩溃_(:3」∠)_</p><h2 id=接口实现类里使用override注解报错>接口实现类里使用@Override注解报错</h2><p>@Override注解用来检测子类对父类或接口的方法的重写是否正确，但有一次我在Eclipse里对接口的实现类里使用@Override注解却报错，不过在父类的子类里使用该注解却是正常的。</p><p>百度了下才知道原来这是jdk1.5时的一个bug，在1.6时已经被修复；那么问题来了，我使用的jdk是1.8，为什么会报这个错误？明明之前也在接口的实现类里用过该注解，却没问题。由于Eclipse经常抽风，我怀疑是Eclipse的问题，经过排查确实如此，该项目使用的jdk版本不知道为什么变成了jdk1.5，导致出现了注解报错的问题。</p><h3 id=解决方法>解决方法</h3><p>右键该项目，选择Properties，将Java Compiler和Java Facets里的jdk版本从1.5改为更高的版本，再刷新下项目重新编译就没问题了。`</p><h2 id=修改默认编码为utf-8>修改默认编码为utf-8</h2><p>一共需要设置三个地方：</p><ol><li>Window -> Preferences -> General -> Content Type -> Text -> JSP，在 最下面设置为UTF-8</li><li>Window -> Preferences -> General -> Workspace，将<code>Text file encoding</code>设置为UTF-8</li><li>Window -> Preferences -> Web -> JSP Files，设置为<code>ISO 10646/Unicode(UTF-8)</code></li></ol><h2 id=修改properties文件的编码>修改properties文件的编码</h2><p>Eclipse的properties文件是默认ISO-8859-1编码的，如果在properties里输入中文会导致乱码，此时需要修改其编码为utf-8，具体步骤如下：</p><p><code>Window -> Preferences -> General -> Content Types -> Text</code>，然后单击<code>Java Properties Files</code>，选定下方的<code>*.properties(locked)</code>，接着将最下方的ISO-8859-1改为utf-8，然后点击旁边的 <code>Update</code>，最后点击OK。</p><h2 id=如何修改web项目的web-module-version>如何修改web项目的web module version</h2><p>有时候我们想改变web项目的web module version，比如说原本是2.4版本，我们想改成3.0版本，通过右键项目名 -> Properties -> Project Facets，选中Dynamic Web Module后边的版本，将2.4改成3.0</p><p>这时候会报错误：<code>Cannot change version of project facet Dynamic Web Module to 3.0.</code></p><p>而且这时候改动web.xml的文件头从2.4改成3.0版本的文件头也会报错。</p><h3 id=解决办法>解决办法</h3><ol><li>这时候我们需要找到该项目的目录，进入.setting文件夹，打开org.eclipse.wst.common.project.facet.core.xml</li><li>我们可以发现在这个xml文件中，有这样一个标签：</li></ol><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-xml data-lang=xml><span class=nt>&lt;installed</span> <span class=na>facet=</span><span class=s>&#34;jst.web&#34;</span> <span class=na>version=</span><span class=s>&#34;2.4&#34;</span><span class=nt>/&gt;</span>
</code></pre></td></tr></table></div></div><ol start=3><li>将这里的version改成你想要的版本，比如改成3.0</li><li>保存该文件的改动，接着刷新Eclipse中的该项目(左键选中项目名，按F5刷新项目)</li><li>接着再去Properties -> Project Facets ， 将Dynamic Web Module改为3.0；然后将web.xml的文件头改为对应3.0版本的文件头；此时会发现可以修改成功而不会报错。</li></ol><h2 id=maven项目update-project后jdk版本变成15>Maven项目Update Project后jdk版本变成1.5</h2><p>在Eclipse里对一个Maven项目进行Update Project(快捷键是 <code>Alt+F5</code>)，原本jdk为1.8的项目忽然就变成了1.5，于是就报了一些错误。</p><p>这跟Maven默认的jdk版本有关系，Maven项目如果不指定编译的jdk版本，就会默认为jdk1.5。查了下项目的pom文件，里边并没有指定编译的jdk版本，而Maven的配置文件settings.xml里也没有指明jdk版本，所以当Update Project后，这个Maven项目就会自动变成jdk1.5了。</p><p>有两种解决方法，一种是针对某个Maven项目而言，直接在pom文件中指明jdk版本；一种是全局设置，为所有Maven项目指明jdk版本。</p><h3 id=方法一在pom文件中指明jdk版本>方法一：在pom文件中指明jdk版本</h3><p>在项目的pom.xml中的build节点里使用maven的编译插件来指定jdk版本，项目中通常使用这种方法来指定，因为比较灵活，可以随意指定版本，修改保存后即可生效。</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span><span class=lnt>11
</span><span class=lnt>12
</span><span class=lnt>13
</span><span class=lnt>14
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-xml data-lang=xml><span class=nt>&lt;build&gt;</span>
    <span class=nt>&lt;plugins&gt;</span>
        <span class=nt>&lt;plugin&gt;</span>
            <span class=nt>&lt;groupId&gt;</span>org.apache.maven.plugins<span class=nt>&lt;/groupId&gt;</span>
            <span class=nt>&lt;artifactId&gt;</span>maven-compiler-plugin<span class=nt>&lt;/artifactId&gt;</span>
            <span class=nt>&lt;version&gt;</span>3.1<span class=nt>&lt;/version&gt;</span>
            <span class=nt>&lt;configuration&gt;</span>
            <span class=nt>&lt;encoding&gt;</span>UTF-8<span class=nt>&lt;/encoding&gt;</span>
            <span class=nt>&lt;source&gt;</span>1.8<span class=nt>&lt;/source&gt;</span>
            <span class=nt>&lt;target&gt;</span>1.8<span class=nt>&lt;/target&gt;</span>
            <span class=nt>&lt;/configuration&gt;</span>
        <span class=nt>&lt;/plugin&gt;</span>
    <span class=nt>&lt;/plugins&gt;</span>
<span class=nt>&lt;/build&gt;</span>
</code></pre></td></tr></table></div></div><h3 id=方法二修改settingsxml文件>方法二：修改settings.xml文件</h3><p>找到Maven的安装路径，打开<code>conf\settings.xml</code>，找到<code>profiles</code>节点，在该节点下添加一个<code>profile</code>节点：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt> 1
</span><span class=lnt> 2
</span><span class=lnt> 3
</span><span class=lnt> 4
</span><span class=lnt> 5
</span><span class=lnt> 6
</span><span class=lnt> 7
</span><span class=lnt> 8
</span><span class=lnt> 9
</span><span class=lnt>10
</span><span class=lnt>11
</span><span class=lnt>12
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-xml data-lang=xml><span class=nt>&lt;profile&gt;</span>
    <span class=nt>&lt;id&gt;</span>jdk-1.8<span class=nt>&lt;/id&gt;</span>
    <span class=nt>&lt;activation&gt;</span>
    <span class=nt>&lt;jdk&gt;</span>1.8<span class=nt>&lt;/jdk&gt;</span>
    <span class=nt>&lt;activeByDefault&gt;</span>true<span class=nt>&lt;/activeByDefault&gt;</span>
    <span class=nt>&lt;/activation&gt;</span>
    <span class=nt>&lt;properties&gt;</span>
    <span class=nt>&lt;maven.compiler.source&gt;</span>1.8<span class=nt>&lt;/maven.compiler.source&gt;</span>
    <span class=nt>&lt;maven.compiler.target&gt;</span>1.8<span class=nt>&lt;/maven.compiler.target&gt;</span>
    <span class=nt>&lt;maven.compiler.compilerVersion&gt;</span>1.8<span class=nt>&lt;/maven.compiler.compilerVersion&gt;</span>
    <span class=nt>&lt;/properties&gt;</span>
<span class=nt>&lt;/profile&gt;</span>
</code></pre></td></tr></table></div></div><p>使用这种方法的好处是所有Maven项目都会按照这里的jdk版本来编译，当然如果在pom文件里也指定了jdk版本，则以pom里的为准。<strong>这种全局修改的方法必须要重启Eclipse才有效果</strong>。</p><p>个人建议就算是修改了全局配置，也要在每个Maven项目里指明jdk版本，这是种良好的规范，利于别人理解。</p><h2 id=安装了jd-eclipse插件后依然无法反编译类文件>安装了jd-eclipse插件后依然无法反编译类文件</h2><p>Eclipse在安装了jd-eclipse插件后依然无法反编译类文件，这个问题是因为没有修改默认的类文件查看器。需要修改默认的类文件查看器为jd-eclipse：</p><ol><li>Window -> Preference -> General -> Editors -> File Associations</li><li>选中<code>*.class</code>，将<code>Class File Editor</code>设置为默认(Default)</li><li>选中<code>*.class without source</code>，将<code>Class File Editor</code>设置为默认(Default)；如果这一步操作只有<code>Class File Viewer</code>，则需要点击<code>Add</code>把<code>Class File Editor</code>添加进来并设置为默认(Default)</li></ol><p>新版本的jd-eclipse的类文件查看器名字可能叫做JD Class File Viewer(总之，Class File Viewer是Eclipse自带的类文件查看器，安装插件后会出现新的类文件查看器)</p><p>接着重启Eclipse后就可以正常地反编译类文件了，如果缺少上述的第三步操作，会有比较大的可能依然无法反编译类文件。</p><h2 id=eclipse无法找到mapstruct生成的mapper实现类>Eclipse无法找到MapStruct生成的mapper实现类</h2><p>Eclipse本身不支持MapStruct，除了需要安装较新版本的m2e插件，还要另外安装插件<code>m2e-apt</code>，该插件可以在Eclipse的Market里搜到。</p><p>接着在pom文件里添加：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span><span class=lnt>2
</span><span class=lnt>3
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-fallback data-lang=fallback>&lt;properties&gt;
        &lt;m2e.apt.activation&gt;jdt_apt&lt;/m2e.apt.activation&gt;
&lt;/properties&gt;
</code></pre></td></tr></table></div></div><p>然后maven update一下项目，重新编译后会在target目录下出现两个文件目录，里面存放的是MapStruct的生成类。</p><p>如果这时候还没效果，要手动打开apt的功能。邮件项目，选择<code>Properties</code> -> <code>Maven</code> -> <code>Annotation Processing</code> -> 勾选<code>Enable project specific settings</code> -> 选择第一个选项<code>Automatically config JDT APT</code> -> <code>Apply and Close</code></p><h2 id=弹窗提示-code-recommenders-cannot-download-its-model-repository-index>弹窗提示 code recommenders cannot download its model repository index</h2><p>原因是该插件的model地址<code>http://download.eclipse.org/recommenders/models/oxygen/</code>已经被移除了，且很久没有更新了，最新版的Eclipse里已经把该地址移除了，旧版本的需要自行移除：</p><p><code>Window</code> -> <code>Preferences</code> -> <code>Code Recommenders</code> -> <code>Models</code> -> 选中这里面的地址，然后点击<code>Remove</code>即可。</p><h2 id=eclipse无法搜索到本地仓库的jar包>Eclipse无法搜索到本地仓库的jar包</h2><p>某次忽然发现无法在Eclipse中搜索到刚刚install好的jar包，来回折腾了好久也无法解决。百度后才知道原因，其实每次打开Eclipse时都会自动更新index索引，可能是出了某种未知的问题，自动更新index失败了，由于index缺失导致无法定位到本地install的新jar包。所以我们需要在Eclipse里手动更新下maven的index索引。</p><p>解决方法如下：</p><ol><li>打开Eclipse的Maven仓库视图：<code>Window</code> -> <code>Show View</code> -> <code>Other...</code> -> <code>Maven Repositories</code></li><li>找到你的本地仓库并重建索引：<code>Local Repositories</code> -> <code>Local Repository</code> -> 右键，选择<code>Rebuild Index</code></li><li>更新完索引后就可以搜索到本地库里最新的jar包了</li></ol><p>如果想搜索远程库的最新依赖(jar包)，操作类似：</p><ol><li>在Maven仓库视图里：<code>Global Repositories</code> -> 选定某个远程库 -> 右键，选择<code>Update Index</code></li><li>更新完索引后就可以搜索到远程库里最新的jar包了</li></ol><h2 id=启动springboot项目报错-error-could-not-find-or-load-main-class>启动SpringBoot项目报错： Error: Could not find or load main class</h2><p>在Eclipse里对一个SpringBoot项目选择<code>Run As</code> -> <code>Maven clean</code>后，通过启动类启动该项目时报错如下：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=nl>Error:</span> <span class=n>Could</span> <span class=n>not</span> <span class=n>find</span> <span class=n>or</span> <span class=n>load</span> <span class=n>main</span> <span class=kd>class</span>
</code></pre></td></tr></table></div></div><p>解决方法是clean该项目并重新编译，再次启动时选择<code>Run As</code> -> <code>Java Application</code>，启动成功。</p><p>还有另一个会触发该错误的方式：</p><p>在Eclipse里启动SpringBoot项目的时候，右键启动类，选择<code>Run As</code>，此时手误点成了<code>Run on Server</code>，之后就一直启动报错如下：</p><div class=highlight><div class=chroma><table class=lntable><tr><td class=lntd><pre class=chroma><code><span class=lnt>1
</span></code></pre></td><td class=lntd><pre class=chroma><code class=language-java data-lang=java><span class=nl>Error:</span> <span class=n>Could</span> <span class=n>not</span> <span class=n>find</span> <span class=n>or</span> <span class=n>load</span> <span class=n>main</span> <span class=kd>class</span>
</code></pre></td></tr></table></div></div><p>解决方法同上。</p><h2 id=参考链接>参考链接</h2><ul><li><a href=https://blog.csdn.net/free4294/article/details/7017442 target=_blank rel="noopener noreffer">解决办法：Access restriction: The type JPEGImageEncoder is not accessible due to restriction</a></li><li><a href=http://blog.sina.com.cn/s/blog_6cfb18070100n7pu.html target=_blank rel="noopener noreffer">缺少servlet-api.jar包</a></li><li><a href=https://jingyan.baidu.com/article/27fa732682e3f446f8271f26.html target=_blank rel="noopener noreffer">怎样设置Eclipse在启动时提示选择工作空间</a></li><li><a href=https://www.cnblogs.com/bianqi/p/6819074.html target=_blank rel="noopener noreffer">maven 修改默认的JDK版本</a></li><li><a href=https://blog.csdn.net/Ashes18/article/details/70488617 target=_blank rel="noopener noreffer">Maven管理项目的时候 Update Project后jre变成1.5</a></li><li><a href=https://zhidao.baidu.com/question/152315060.html target=_blank rel="noopener noreffer">安装jadClipse插件后,还是不能反编译.class</a></li><li><a href=https://blog.csdn.net/u014519194/article/details/54410391 target=_blank rel="noopener noreffer">mapstruct在eclipse生成不了mapper的实现类的问题</a></li><li><a href=https://blog.csdn.net/sjc170/article/details/102961231 target=_blank rel="noopener noreffer">eclipse 报错 code recommenders cannot download its model repository index-已解决</a></li><li><a href=https://blog.csdn.net/weixin_34289744/article/details/86033158 target=_blank rel="noopener noreffer">在eclipse的maven插件中搜寻本地仓库中的jar搜索不到的解决方案</a></li></ul><div class=post-reward><input type=checkbox name=reward id=reward hidden>
<label class=reward-button for=reward>赞赏支持</label><div class=qr-code><label class=qr-code-image for=reward><img class=image src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/common/wechat.png>
<span>微信打赏</span></label>
<label class=qr-code-image for=reward><img class=image src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/common/alipay.png>
<span>支付宝打赏</span></label></div></div></div><div class=post-footer id=post-footer><div class=post-info><div class=post-info-line><div class=post-info-mod><span>更新于 2022-01-12</span></div><div class=post-info-license><span><a rel="license external nofollow noopener noreffer" href=https://creativecommons.org/licenses/by-nc/4.0/ target=_blank>CC BY-NC 4.0</a></span></div></div><div class=post-info-line><div class=post-info-md><span><a class=link-to-markdown href=/posts/eclipse-issues/index.md target=_blank>阅读原始文档</a></span></div><div class=post-info-share><span><a href=javascript:void(0); title="分享到 Twitter" data-sharer=twitter data-url=https://lewky.cn/posts/eclipse-issues/ data-title=Eclipse问题汇总 data-hashtags=Eclipse,工作记录><i class="fab fa-twitter fa-fw"></i></a><a href=javascript:void(0); title="分享到 Facebook" data-sharer=facebook data-url=https://lewky.cn/posts/eclipse-issues/ data-hashtag=Eclipse><i class="fab fa-facebook-square fa-fw"></i></a><a href=javascript:void(0); title="分享到 Hacker News" data-sharer=hackernews data-url=https://lewky.cn/posts/eclipse-issues/ data-title=Eclipse问题汇总><i class="fab fa-hacker-news fa-fw"></i></a><a href=javascript:void(0); title="分享到 Line" data-sharer=line data-url=https://lewky.cn/posts/eclipse-issues/ data-title=Eclipse问题汇总><i data-svg-src=https://cdn.jsdelivr.net/npm/simple-icons@2.14.0/icons/line.svg></i></a><a href=javascript:void(0); title="分享到 微博" data-sharer=weibo data-url=https://lewky.cn/posts/eclipse-issues/ data-title=Eclipse问题汇总><i class="fab fa-weibo fa-fw"></i></a></span></div></div></div><div class=post-info-more><section class=post-tags><i class="fas fa-tags fa-fw"></i>&nbsp;<a href=/tags/eclipse/>Eclipse</a>,&nbsp;<a href=/tags/%E5%B7%A5%E4%BD%9C%E8%AE%B0%E5%BD%95/>工作记录</a></section><section><span><a href=javascript:void(0); onclick=window.history.back();>返回</a></span>&nbsp;|&nbsp;<span><a href=/>主页</a></span></section></div><div class=post-nav><a href=/posts/a28e251d.html/ class=prev rel=prev title=Windows下MySQL8.0.13解压版安装教程><i class="fas fa-angle-left fa-fw"></i>Windows下MySQL8.0.13解压版安装教程</a>
<a href=/posts/9af9bb6b.html/ class=next rel=next title="执行gulp build报错">执行gulp build报错<i class="fas fa-angle-right fa-fw"></i></a></div></div><div id=comments><div id=waline></div><script src=https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js></script><script>new Waline({el:'#waline',meta:["nick","mail","link"],requiredMeta:["nick","mail"],login:"force",placeholder:"为防恶意灌水攻击，评论前需注册并登录，望见谅~",serverURL:"https://comment.lewky.cn/",avatarCDN:"https://sdn.geekzu.org/avatar/",pageSize:20,avatar:"retro",lang:"zh-CN",visitor:true,highlight:true,uploadImage:false,emoji:['https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/嘉然今天吃什么','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/大航海嘉然','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/向晚大魔王','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/贝拉kira','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/珈乐Carol','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/乃琳Queen','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/EveOneCat','https://cdn.jsdelivr.net/gh/walinejs/emojis@1.0.0/weibo','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/滑稽','https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/emoji/default']});</script></div></article></div></main><footer class=footer><div class=footer-container><div class=footer-line><span id=run-time></span>|
<a href=http://rssblog.vercel.app/ target=_blank rel=noopener title=RSSBlog><i class="fas fa-fw fa-inbox"></i>&nbsp;RSSBlog</a></div><div class=footer-line><i class="far fa-copyright fa-fw"></i><span itemprop=copyrightYear>2018 - 2022</span><span class=author itemprop=copyrightHolder>&nbsp;<a href=/ target=_blank>雨临Lewis</a></span>&nbsp;|&nbsp;<span class=license><a rel="license external nofollow noopener noreffer" href=https://creativecommons.org/licenses/by-nc/4.0/ target=_blank>CC BY-NC 4.0</a></span><span class=icp-splitter>&nbsp;|&nbsp;</span><br class=icp-br><span class=icp><a target=_blank href=http://www.beian.miit.gov.cn/ style=font-weight:700>粤ICP备19103822</a></span></div></div></footer></div><div id=fixed-buttons><a href=# id=back-to-top class=fixed-button title=回到顶部><i class="fas fa-arrow-up fa-fw"></i></a><a href=# id=view-comments class=fixed-button title=查看评论><i class="fas fa-comment fa-fw"></i></a></div><div class=sidebar_wo><div id=leimu><img src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/b2t/leimuA.png alt=雷姆 onmouseover="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/leimuB.png'" onmouseout="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/leimuA.png'" title=回到顶部></div><div class=sidebar_wo id=lamu><img src=https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master/images/b2t/lamuA.png alt=雷姆 onmouseover="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/lamuB.png'" onmouseout="this.src='https:\/\/cdn.jsdelivr.net\/gh\/lewky\/lewky.github.io@master/images/b2t/lamuA.png'" title=回到底部></div></div><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/css/lightgallery.min.css><script type=text/javascript src=https://cdn.jsdelivr.net/npm/smooth-scroll@16.1.3/dist/smooth-scroll.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lazysizes@5.2.2/lazysizes.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/js/lightgallery.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lg-thumbnail.js@1.2.0/dist/lg-thumbnail.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/lg-zoom.js@1.2.0/dist/lg-zoom.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/sharer.js@0.4.0/sharer.min.js></script><script type=text/javascript>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":30},"comment":{},"lightGallery":{"actualSize":false,"exThumbImage":"data-thumbnail","hideBarsDelay":2000,"selector":".lightgallery","speed":400,"thumbContHeight":80,"thumbWidth":80,"thumbnail":true}};</script><script type=text/javascript src=/js/theme.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/jquery@2.1.3/dist/jquery.min.js></script><script type=text/javascript src=https://cdn.jsdelivr.net/npm/jquery-backstretch@2.1.18/jquery.backstretch.min.js></script><script>var $cdnPrefix="https://cdn.jsdelivr.net/gh/lewky/lewky.github.io@master";</script><script type=text/javascript src=/js/custom.js></script><script>var _hmt=_hmt||[];(function(){var hm=document.createElement("script");hm.src="https://hm.baidu.com/hm.js?6f278ed0fdb01edb3b1e7398379e5432";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm,s);})();</script></body></html>